package com.itheima.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.itheima.pojo.Customer;

/**
 * dao层接口
 * 规范：
 * 		1、接口所在的包已经在核心配置文件中指定了
 * 		2、这个接口需要继承两个接口：
 * 					基本的分页CRUD：  JpaRepository<操作的实体类,主键的类型>
 * 					复杂动态查询：         JpaSpecificationExecutor<操作的实体类>
 * 
 * 
 * @author Johnny.Chen
 *
 */
public interface CustomerDao extends JpaRepository<Customer, Long>,JpaSpecificationExecutor<Customer>{

	@Query(value="from Customer where custName = ?1 or custLevel like ?2")
	public List<Customer> findJPQL2(String name,String level);
	
	@Query(value="from Customer where custName = ?1")
	public List<Customer> findJPQL1(String name);
	
	@Modifying //更新的jpql需要这个标记
	@Query(value="update Customer set custName = ?2 where custId = ?1")
	public void updateJpql(Long id,String name);
	
	
	@Query(value="SELECT * FROM cst_customer WHERE cust_id >= ?1  AND cust_level LIKE ?2",nativeQuery=true)
	public List<Customer> findSQL(Long id, String level);
	
	
	//===============================================================================
	//===================         根据方法命名查询           ========================
	//===============================================================================
	
	//精确查询
	public Customer findByCustName(String name);
	
	//模糊查询
	public List<Customer> findByCustNameLike(String name);
	
	//多条件
	public List<Customer> findByCustNameLikeAndCustLevel(String name,String level);
}






















